home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The X-Philes (2nd Revision)
/
The X-Philes Number 1 (1995).iso
/
xphiles
/
coding
/
dsp
/
bfltlib.exe
/
LNG_SQRT.ASM
< prev
next >
Wrap
Assembly Source File
|
1991-05-14
|
2KB
|
67 lines
;**************************************************************
;
; lng_sqrt.asm
;
; Keith Larson
;
; 05-14-91
;
; (C) Texas Instruments Inc., 1992
;
; Refer to the file 'license.txt' included with this
; this package for usage and license information.
;
;**************************************************************
***********************************************************
* lng_sqrt.asm (C callable) *
* Written By Keith Larson 4/24/91 *
* DSP Applications *
* Texas Instruments *
* s |-----------| This routine uses a succesive *
* t | AR0 | approximation technique that *
* a |-----------| holds both the test bit and *
* c | AR2 | the guess in ARx registers *
* k |-----------| *
* entry> | guess | mem config |pi/di|pe/de| *
* |-----------| -------------|-----|-----| *
* | input hi | cycles (pos) | |~300 | *
* |-----------| (0/neg) | 7 | 7 | *
* | input lo | *
* |-----------| *
***********************************************************
.global _lng_sqrt
_lng_sqrt:
blez ret_0 ;
adrk 2 ; >AR0
sar AR0,*- ;store AR0 >AR2
sar AR2,*- ;store AR2 >AR3
lrlk AR0,08000h ;initial test bit
lrlk AR2,08000h ;initial guess 0
;------------------------------------------------;
; This section performs successive aproximation ;
;------------------------------------------------;
more: sar AR2,* ;store guess
lt * ;square guess (unsigned)
mpyu *- ;
pac ;
subh *- ;ACCU = guess - input
subs *+ ;
mar *+,AR0 ;
bgz to_hi,*BR0+,AR2 ;AR0>>1; guess^2 > input?
to_low mar *0+,AR0 ;add test bit if guess too low
banz more,*,AR1 ;more test bits?
b done ;
to_hi: mar *0-,AR0 ;sub test bit if guess too high
banz more,*,AR1 ;more test bits
larp AR2 ;Always +1 LSB error
mar *-,AR1 ;subtract LSB
done: sar AR2,* ;store final guess (result)
zals *+ ;load result in ACCU
lar AR2,*+ ;restore AR0 & AR2
lar AR0,* ;
sbrk 2 ;restore AR1
ret ;
ret_0: zac ;if input <=0
ret ;then return 0
.end